<template>
  <div class="wrapper">
    <div class="header">
      <div class="login">
        <b>家庭记账系统</b>
      </div>
      <!-- 登录时前端进行验证 -->
      <el-form :model="user">
        <el-form-item prop="username">
          <el-input placeholder="请输入账号" size="medium" prefix-icon="el-icon-user" v-model="user.username"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input placeholder="请输入密码" size="medium" prefix-icon="el-icon-lock" show-password
            v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item class="btn">
          <el-button type="warning" size="small" autocomplete="off" @click="register">注册</el-button>
          <el-button type="primary" size="small" autocomplete="off" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template> 

<script>
import { registerUser } from '@/api/admin/user/User';
export default {
  name: "Login",
  data() {
    return {
      user: {},
    };
  },
  methods: {
    login(){
      this.$router.push("/login")
    },
    register() {
      registerUser(this.user).then(response => {
        if (response.code == 200) {
          this.$message.success("注册成功");
        } else {
          this.$message.error(response.message);
        }
      })
    }
  }
};
</script>

<style scoped>
.wrapper {
  background-image: url(../../assets/img/bg.png);
  background-size: cover;
    height: 100vh; /* 根据需要调整 */
    background-position: center;
	display: flex;
}

.header {
  margin: 150px auto;
  background-color: #fff;
  width: 350px;
  height: 200px;
  padding: 20px 20px 40px 20px;
  border-radius: 10px;
}

.login {
  margin: 20px 0;
  text-align: center;
  font-size: 24px;
}

.btn {
	display: flex;
  margin: 10px 0;
  justify-content: space-around;
}
</style>
